    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
function changeSate(id, state) {
    $.ajax({
        type: 'POST',
        url: "changeState",
        data: {
            id: id,
            state: state
        },
        success: function () {
            $('#mytable').bootstrapTable('refresh', {url: '/admin/fanconfig/list'});
        },
        dataType: "json"
    });
}

function deleteOne(id) {
    swal({
        title: '您确定要删除此行数据？',
        text: '你将无法恢复它！',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#ed5666',
        confirmButtonText: '确定删除！',
        cancelButtonText: '取消删除！',
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false
    }).then(function () {
        $.ajax({
            type: 'POST',
            url: "deleteOne",
            data: {
                id: id,
            },
            success: function (status) {
                if (status == 1) {
                    swal({title: "删除成功", text: "", type: "success"})
                    $('#mytable').bootstrapTable('refresh', {url: '/admin/fanconfig/list'});
                } else {
                    swal({title: "删除失败", text: "", type: "error"})
                }
            },
            dataType: "json"
        });

    }, function (dismiss) {
        // dismiss的值可以是'cancel', 'overlay',
        // 'close', 'timer'
        if (dismiss === 'cancel') {
            swal({title: '您已取消操作！', text: '', timer: 2000})
        }
    })
}

var editsw=[];
/**
 * 为模态框填充数据
 */
$('#modal-form').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); // 触发事件的按钮
    var id = button.data('row');
    console.log(button.data('row'))
    var modal = $(this);
    $.ajax({
        type: 'POST',
        url: "getFanConfigById",
        data: {
            id: id
        },
        success: function (data) {
            console.log(data)
                                                modal.find('#id').val(data.id)
                                                                modal.find('#zhuceType').find("option[value='"+data['zhuceType']+"']").attr("selected",true);

                                                                modal.find('#zhuceMount').val(data.zhuceMount)
                                                                modal.find('#shoujifanType').find("option[value='"+data['shoujifanType']+"']").attr("selected",true);

                                                                modal.find('#shoujifanMount').val(data.shoujifanMount)
                                                                modal.find('#nuserfanType').find("option[value='"+data['nuserfanType']+"']").attr("selected",true);

                                                                modal.find('#nuserfanMount').val(data.nuserfanMount)
                                                                modal.find('#zffanType').find("option[value='"+data['zffanType']+"']").attr("selected",true);

                                                                modal.find('#zffanMount').val(data.zffanMount)
                                                                modal.find('#zffanMax').val(data.zffanMax)
                                                                modal.find('#signfanType').find("option[value='"+data['signfanType']+"']").attr("selected",true);

                                                                modal.find('#signfanMount').val(data.signfanMount)
                                                                modal.find('#readfanType').find("option[value='"+data['readfanType']+"']").attr("selected",true);

                                                                modal.find('#readfanMount').val(data.readfanMount)
                                                                modal.find('#readfanMax').val(data.readfanMax)
                                                                modal.find('#zanType').find("option[value='"+data['zanType']+"']").attr("selected",true);

                                                                modal.find('#zanMount').val(data.zanMount)
                                                                modal.find('#zanMax').val(data.zanMax)
                                                                editsw["state"] == undefined ? editsw["state"] = new Switchery(document.querySelector('#state'), {color: "#1AB394"}) : ""
                    if (data.isMember == 1) {
                        setSwitchery(editsw["state"], true);
                    } else {
                        setSwitchery(editsw["state"], false);
                    }
                                                                                                            modal.find('#sid').val(data.sid)
                                                                                                            modal.find('#creator').val(data.creator)
                                                                                                            modal.find('#modifior').val(data.modifior)
                            
            if(data.state==1){
                modal.find('#state').attr("checked",'checked').val("1");
            }
        },
        dataType: "json"
    });
})

//tableHeight函数
function tableHeight(){
    //可以根据自己页面情况进行调整
    return $(window).height() -200;
}
$(function() {
    var sw = [];
    $(".js-switch").each(function (i,e) {
        sw[i] = new Switchery(e, {color: "#1AB394"})
    })

    $(window).resize(function () {
        $('#mytable').bootstrapTable('resetView', {
            height: tableHeight()
        })
    })

    //生成用户数据
    $('#mytable').bootstrapTable({
        method: 'get',
        url:"/admin/fanconfig/list",
        // height:520,//高度调整
        // toolbar: '#toolbar',
        striped: true, //是否显示行间隔色
        dataField: "records",
        pagination:true,//是否分页
        queryParamsType:'limit',
        queryParams:queryParams,
        sidePagination:'server',
        pageNumber: 1, //初始化加载第一页，默认第一页
        pageSize:50,//单页记录数
        pageList:[50,100,200,500],//分页步进值
        showExport:true,//显示导出
        showRefresh:false,//刷新按钮
        showColumns:false,
        clikToSelect: true,//是否启用点击选中行
        // toolbarAlign:'right',
        // buttonsAlign:'right',//按钮对齐方式
        columns:[
             {
                 title:'全选',
                 field:'select',
                 checkbox:true,
                 width:25,
                 align:'center',
                 valign:'middle'
            },
            {
                title:'ID',
                field:'id',
                visible:false
            },
                                                                                                    {
                            title:'新用户首次注册奖励类型',
                            field:'zhuceType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'新用户首次注册奖励额#积分|现金|优惠券|虚拟币',
                            field:'zhuceMount'
                        },
                                                                                                            {
                            title:'绑定手机奖励类型',
                            field:'shoujifanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'绑定手机奖励额#积分|现金|优惠券|虚拟币',
                            field:'shoujifanMount'
                        },
                                                                                                            {
                            title:'拉新用户注册奖励类型',
                            field:'nuserfanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'拉新用户奖励额#积分|现金|优惠券|虚拟币',
                            field:'nuserfanMount'
                        },
                                                                                                            {
                            title:'转发享奖励类型',
                            field:'zffanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'转发奖励额#积分|现金|优惠券|虚拟币',
                            field:'zffanMount'
                        },
                                                                                                            {
                            title:'每日最多转发最高奖励次数',
                            field:'zffanMax'
                        },
                                                                                                            {
                            title:'签到奖励类型',
                            field:'signfanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'签到奖励额#积分|现金|优惠券|虚拟币',
                            field:'signfanMount'
                        },
                                                                                                            {
                            title:'阅读奖励类型',
                            field:'readfanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'阅读奖励额#积分|现金|优惠券|虚拟币',
                            field:'readfanMount'
                        },
                                                                                                            {
                            title:'每日阅读奖最高励额次数',
                            field:'readfanMax'
                        },
                                                                                                            {
                            title:'点赞奖励类型',
                            field:'zanType',
                            formatter:"typeFormatter"
                        },
                                                                                                            {
                            title:'点赞奖励额#积分|现金|优惠券|虚拟币',
                            field:'zanMount'
                        },
                                                                                                            {
                            title:'每日点赞奖最高励额次数',
                            field:'zanMax'
                        },
                                                                                                                                                                                                                                                                {
                title:'操作',
                field:'Attribute',
                align:'center',
                formatter:actionFormatter
            }
        ],
        locale:'zh-CN',//中文支持,
    })

    //请求服务数据时所传参数
    function queryParams(params) {
        var p = {
            limit: params.limit,
            offset:params.offset,
            sort:params.sort,
            order:params.order,
            search:$('#search').val(),
            status:$('#qstatus').val()
        }
        console.log(p)
        return p;
    }

    $('#search_btn').click(function(){
        var params = {
            status:$('#qstatus').val(),
            search:$('#search').val(),
            ts:new Date().getTime()
        };
        console.log(params);
        $('#mytable').bootstrapTable('refresh', params);
    })

})